<?php

namespace app\index\controller\paymentcallback;

use app\index\service\payments\WxpayPaymentService;
use think\APP;
use think\Request;

/**
 * 微信支付回调
 * Class Wxpay
 * @package app\index\controller\paymentcallback
 */
class Wxpay
{
    /**
     * 微信支付回调
     */
    public function index(Request $request)
    {
        $result = $this->getWxpayPaymentService()->payCallback($request);
        $code = 200;
        if ($result['code'] != 'SUCCESS') {
            $code = 500;
        }
        return json($result, $code);
    }

    /**
     * 微信退款回调
     */
    public function refund(Request $request)
    {
        $result = $this->getWxpayPaymentService()->refundCallback($request);
        $code = 200;
        if ($result['code'] != 'SUCCESS') {
            $code = 500;
        }
        return json($result, $code);
    }

    private function getWxpayPaymentService(): WxpayPaymentService
    {
        return \app(WxpayPaymentService::class);
    }

}
